package com.mind.ridge.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mind.ridge.pojo.backend.Employee;
import com.mind.ridge.service.backend.EmpService;
import com.mind.ridge.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Mind
 */
@RestController
@Slf4j
@RequestMapping("/employee")
public class EmpController {

    @Autowired
    private EmpService empService;

    @PostMapping("/login")
    public R<Employee> login(@RequestBody Employee employee, HttpServletRequest request) {
        return empService.login(request, employee);
    }

    @PostMapping("/logout")
    public R logout(HttpServletRequest request) {
        return empService.logout(request);
    }

    @PostMapping
    public R addEmp(HttpServletRequest request, @RequestBody Employee employee) {
        return empService.addEmp(request, employee);
    }

    @GetMapping("/page")
    public R<IPage> page(int page, int pageSize, String name) {
        return empService.page(page, pageSize, name);
    }

    @PutMapping
    public R<String> update(HttpServletRequest request,@RequestBody Employee employee){
        return empService.updateEmp(request,employee);
    }

    @GetMapping("/{id}")
    public R<Employee> echoInfo(@PathVariable String id){
        return empService.echoInfo(id);
    }
}

